from Products.CMFCore.utils import getToolByName
from StringIO import StringIO

def install(self):
    out = StringIO()
    addCatalogIndexes(self, out)


def addCatalogIndexes(self, out):
    """
    Adiciona novos indices no catalogo.
    """

    catalog = 'portal_catalog'
    index = 'title_or_id'
    portal_catalog = getToolByName(self, catalog)

    if index not in portal_catalog.indexes():
        portal_catalog.addIndex(index, 'FieldIndex')
        print >> out, 'Index added to %s: %s' % (catalog, index)
        portal_catalog.reindexIndex(index, None)
        print >> out, 'Reindexed %s index.' % index
    else:
        print >> out, 'Index already exists at %s: %s' % (catalog, index)

def uninstall(self):
    pass

